Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<xstring>: constexpr string element lifetime #3334

Merged
merged 3 commits into from
Jan 12, 2023

Conversation

CaseyCarter
Copy link
Member

@CaseyCarter CaseyCarter commented Jan 9, 2023

I've never trusted our use of _Traits::assign to start the lifetimes of the elements given that, err, that's not what _Traits::assign does. Let's use a construct_at loop instead, and centralize it into a helper function instead of repeating nine times.

Test coverage is in libcxx - 7 skips fixed!

Drive-by: Use _Traits::copy instead of _Traits::move in _Construct. Since we're constructing a new string, we know the argument doesn't alias our content.

I've never trusted our use of `_Traits::assign` to start the lifetimes of the elements given that, err, that's not what `_Traits::assign` does. Let's use a `construct_at` loop instead, and centralize it into a helper function instead of repeating nine times.

Test coverage will be in a future LLVM update.

Drive-by: Use `_Traits::copy` instead of `_Traits::move` in `_Construct`. Since we're constructing a new string, we now the argument doesn't alias our content.
@CaseyCarter CaseyCarter added the bug Something isn't working label Jan 9, 2023
@CaseyCarter CaseyCarter requested a review from a team as a code owner January 9, 2023 08:09
stl/inc/xstring Outdated Show resolved Hide resolved
Copy link
Contributor

@strega-nil-ms strega-nil-ms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good! We may want to make _Activate_SSO_buffer call _Start_element_lifetimes as well.

@CaseyCarter
Copy link
Member Author

CaseyCarter commented Jan 10, 2023

This looks good! We may want to make _Activate_SSO_buffer call _Start_element_lifetimes as well.

I'm happy for SSO activation to continue to use union member assignment to start the element lifetimes. This does at least suggest that _Start_element_lifetimes is too generic a name, however. I'll think about changing it.

EDIT: _Start_element_lifetimes is not too generic, it would work for both cases, but I suspect _Activate_SSO_buffer has better throughput. I added some explanatory comments.

Address STL's review comment, and clarify the difference between _Activate_SSO_buffer and _Start_element_lifetimes.
@StephanTLavavej StephanTLavavej self-assigned this Jan 11, 2023
@StephanTLavavej
Copy link
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej StephanTLavavej merged commit 72229ff into microsoft:main Jan 12, 2023
@StephanTLavavej
Copy link
Member

Thanks for finding out how to fix these libcxx skips, and centralizing all of the duplicated code here! 😻 🚀 😻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants